﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Event_Planner.Filters;

namespace Event_Planner
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801


    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
    public class AllowAnonymousAttribute : Attribute { }


    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());

            filters.Add(new LogonAuthorize());

        }


        public override string GetVaryByCustomString(HttpContext context, string arg)
        {

            if (arg == "Cache.OutputCacheEventosGeneral")
                {
                    return Cache.OutputCacheEventosGeneral;
                }
            else if (arg == "Cache.OutputCacheEventosPropios")
                    {
                      return Cache.OutputCacheEventosPropios;
                    }
                else
                {
                    return base.GetVaryByCustomString(context, arg);
                }

        }


        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }


        protected void Application_Start()
        {
           
            AreaRegistration.RegisterAllAreas();


            System.Data.Entity.Database.SetInitializer<Event_Planner.Models.EventPlannerContext>(new Event_Planner.DataAccess.Inicializar());


            HttpContext.Current.Cache.Insert("Pages", DateTime.Now, null,System.DateTime.MaxValue, System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, null);

            RegisterGlobalFilters(GlobalFilters.Filters);

            RegisterRoutes(RouteTable.Routes);





        }
    }
}

